package com.lineage.data.item_etcitem.extra;

import com.lineage.data.cmd.EnchantAccessory;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.log.PlayerLogUtil;
import java.sql.Timestamp;
import java.util.Random;

public class OrimAccessory extends ItemExecutor {
  private int typelv;
  
  private int a;
  
  private int b;
  
  private int c;
  
  private int d;
  
  private int e;
  
  private int f;
  
  private int g;
  
  private int h;
  
  private int i;
  
  private boolean type2 = false;
  
  public static ItemExecutor get() {
    return new OrimAccessory();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int targObjId = data[0];
    L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
    if (tgItem == null)
      return; 
    if (tgItem.isEquipped()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("(预防误点机制启动)装备中无法强化"));
      return;
    } 
    if (tgItem.isSeal()) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage(String.valueOf(tgItem.getLogName()) + "处于绑定状态！"));
      return;
    } 
    int safe_enchant = tgItem.getItem().get_safeenchant();
    boolean isErr = false;
    int use_type = tgItem.getItem().getUseType();
    switch (use_type) {
      case 23:
      case 24:
      case 37:
      case 40:
        if (tgItem.getItem().get_greater() == 3)
          isErr = true; 
        if (safe_enchant < 0)
          isErr = true; 
        break;
      default:
        isErr = true;
        break;
    } 
    if (tgItem.getBless() >= 128)
      isErr = true; 
    if (isErr) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
      return;
    } 
    int enchant_level = tgItem.getEnchantLevel();
    if (enchant_level == this.typelv) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
      return;
    } 
    pc.getInventory().removeItem(item, 1L);
    Random random = new Random();
    EnchantAccessory enchantAccessory = new EnchantAccessory();
    int lv = 0;
    if (tgItem.getEnchantLevel() == 0) {
      lv = this.a;
    } else if (tgItem.getEnchantLevel() == 1) {
      lv = this.b;
    } else if (tgItem.getEnchantLevel() == 2) {
      lv = this.c;
    } else if (tgItem.getEnchantLevel() == 3) {
      lv = this.d;
    } else if (tgItem.getEnchantLevel() == 4) {
      lv = this.e;
    } else if (tgItem.getEnchantLevel() == 5) {
      lv = this.f;
    } else if (tgItem.getEnchantLevel() == 6) {
      lv = this.g;
    } else if (tgItem.getEnchantLevel() == 7) {
      lv = this.h;
    } else if (tgItem.getEnchantLevel() == 8) {
      lv = this.i;
    } 
    if (random.nextInt(100) <= lv) {
      enchantAccessory.successEnchant(pc, tgItem, 1);
      欧林饰品强化成功记录表("IP(" + pc.getNetConnection().getIp() + ")" + "玩家" + ":【 " + pc.getName() + " 】 " + "的" + "【  " + 
          tgItem.getEnchantLevel() + " " + tgItem.getName() + "】(强化成功)" + "时间:" + "(" + 
          new Timestamp(System.currentTimeMillis()) + ")。");
    } else if (item.getBless() == 0) {
      enchantAccessory.successEnchant(pc, tgItem, 0);
    } else {
      if (tgItem.getEnchantLevel() == 0) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
        return;
      } 
      if (this.type2)
        enchantAccessory.successEnchant(pc, tgItem, -1); 
      欧林饰品强化失败记录表("IP(" + pc.getNetConnection().getIp() + ")" + "玩家" + ":【 " + pc.getName() + " 】 " + "的" + "【 " + 
          tgItem.getEnchantLevel() + " " + tgItem.getName() + "】(强化失败-1)" + "时间:" + "(" + 
          new Timestamp(System.currentTimeMillis()) + ")。");
    } 
    if (enchant_level < -6)
      enchantAccessory.failureEnchant(pc, tgItem); 
  }
  
  public static void 欧林饰品强化失败记录表(String info) {
    PlayerLogUtil.writeLog("[欧林饰品强化[失败]记录表]", info);
  }
  
  public static void 欧林饰品强化成功记录表(String info) {
    PlayerLogUtil.writeLog("[欧林饰品强化[成功]记录表]", info);
  }
  
  public void set_set(String[] set) {
    try {
      this.typelv = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
    try {
      this.a = Integer.parseInt(set[2]);
    } catch (Exception exception) {}
    try {
      this.b = Integer.parseInt(set[3]);
    } catch (Exception exception) {}
    try {
      this.c = Integer.parseInt(set[4]);
    } catch (Exception exception) {}
    try {
      this.d = Integer.parseInt(set[5]);
    } catch (Exception exception) {}
    try {
      this.e = Integer.parseInt(set[6]);
    } catch (Exception exception) {}
    try {
      this.f = Integer.parseInt(set[7]);
    } catch (Exception exception) {}
    try {
      this.g = Integer.parseInt(set[8]);
    } catch (Exception exception) {}
    try {
      this.h = Integer.parseInt(set[9]);
    } catch (Exception exception) {}
    try {
      this.i = Integer.parseInt(set[10]);
    } catch (Exception exception) {}
    try {
      this.type2 = Boolean.parseBoolean(set[11]);
    } catch (Exception exception) {}
  }
}
